<template>
  <PageMain>
    <template #header></template>
    <template #body>
      <div class="main-container">
        <CellDesc title="基础信息" :list="list" />
        <CellTitle title="版本信息" />
        <Tables  :columns="columns" operatorInfo="查看" @goToDetails="goDetails"></Tables>
     
      </div>
      <!-- <div class="top-box w-[calc(100%_-_48px)] h-[60px] m-[20px_24px]  box-border p-[14px_24px] bg-[#F7F9FC]">
        <a-row>
          <a-col :span="12">
            <a-form-item label="资源名称">{{ dataItme.name }}</a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="资源编号">{{ dataItme.code }}</a-form-item>
          </a-col>
        </a-row>
      </div>
      <div class="ver-table-list w-full h-[calc(100%_-_164px)] overflow-hidden box-border p-[0_24px_10px_24px]">
        <a-table :columns="Columns" :data="verlistData.versions" :pagination="false" :scroll="{ x:0, y:'100%' }">
          <template #version="{ record }">
            <pre>V {{ record.version }}.0</pre>
          </template>
          <template #operation="{record}">
            <a-link type="primary" @click="toView(record)">查看</a-link>
          </template>
        </a-table>
      </div>
      <div 
        class="w-full h-[64px] overflow-hidden box-border flex justify-between items-center p-[0_24px] text-[#000]"
        style="box-shadow: 0px 0px 6px 0px rgba(57, 77, 115, 0.1);"  
      >
        <span></span>
        <span>
          <a-button type="primary" @click="$router.push({ name: 'resourceManagementList' })">关闭</a-button>
        </span>
      </div> -->
    </template>
  </PageMain>
  <div class="version-list-box">
  </div>
</template>

<script lang="ts" setup>
import * as Api from '@/api/assetManagement/assetManagement';
import * as T from '@/api/assetManagement/assetManagement_type';
import PageMain from '@/components/PageBox.vue';
import CellDesc from '@/views/resource_ledger/components/CellDesc.vue';
import CellTitle from '@/views/resource_ledger/components/CellTitle.vue';
import Tables from '@/views/resource_ledger/components/Tables.vue';
import { Message } from '@arco-design/web-vue';
import { onMounted, ref } from 'vue';
import { useRoute, useRouter } from 'vue-router';

// import { Columns } from './values';

const router = useRouter();
const route = useRoute();
const dataItme = ref<T.TResourceItem>(T.DefaultTResourceItem())
const page = ref({
  page: 1, page_size: 10, total: 0
})

const dataId = ref<string|number>(route.params.id as any)
const verlistData = ref<T.TResourceVerItem>([])
  const list = ref([
  {
    name: '资源名称：',
    value: '测销售订单数据'
  },
  {
    name: '资源编号：',
    value: 'SOO10'
  }
  ])

  const columns = [
      {
        title: '资源版本',
        dataIndex: 'name',
        // main-container
      },
      {
        title: '录入人',
        dataIndex: 'salary',
      },
      {
        title: '添加时间',
        dataIndex: 'address',
      },
      {
        title: '更新时间',
        dataIndex: 'email',
      },
      {
        title: '操作',
        slotName: 'operator',
        width: 70,
        fixed: 'right',
      }
    ]
function toView(item: any) {
  const {id} = item;
  if(id) {
    router.push({ name: 'resourcecheck', params: { id } });
  }
}

function getVersions() {
  Api.GetVers(page.value, dataItme.value.code).then((rs) => {
    const { code, data } = rs;
    if (code === 200 && data) {
      verlistData.value = data;
      return
    }
    Message.error(`获取资源版本信息失败[${rs.errMsg}]`);
  });
}

function getData() {
  Api.GetResourceInfo(dataId.value).then((rs) => {
    const { code, data } = rs;
    if (code === 200 && data) {
      dataItme.value = data;
      getVersions()
      return
    }
    Message.error(`获取资源信息失败[${rs.errMsg}]`);
  });
}

const goDetails = (val) => {
  console.log(val)
  router.push({ name: 'resourcecheck', params: { id:val.id } });
  // router.push({ name: 'resourceView', params: { id: dataId.value } });
}

onMounted(() => {
  getData()
});


</script>

<style lang="less" scoped>
.main-container{
  height: 100%;
  overflow-y: scroll;
  padding: 0 24px 20px;
}
</style>
